#-*- coding:utf-8 -*-

import pygame
import sys
import math
from pygame.locals import *
#from stars import *

WINC = 'Winc'

class planet:
    def __init__(self, img, dx, roll, log, hide):
        self.pos_x = self.pos_y = 0
        self.log = log
        self.d = int(dx)
        self.dx = int(dx)
        self.hd = hide
        self.roll = roll
        self.roll_t = 0
        self.planet_img = pygame.image.load(img)
    
    def img(self):
        img = pygame.transform.scale(self.planet_img, (int(self.d), int(self.d)))
        return img
    
    def up(self, up=1.1):self.d *= up
    
    def low(self, low=0.9):self.d *= low

    def center(self):
        return -self.pos_x, -self.pos_y

    def update(self, screen, size, win, o=WINC):
        self.roll_t += self.roll
        if o == 'Winc':
            ox = size[0]//2
            oy = size[1]//2
        else:
            ox = o.pos_x
            oy = o.pos_y
        self.pos_x = int(ox + size[1]//self.log*math.sin(self.roll_t)*self.d/self.dx)
        self.pos_y = int(oy + size[1]//self.log*math.cos(self.roll_t)*self.d/self.dx)
        screen.blit(self.img(),[self.pos_x-self.d/2+win[0], self.pos_y-self.d/2+win[1]])

pygame.init()
size = width, height = 1000, 600
screen = pygame.display.set_mode(size,RESIZABLE)
myfont=pygame.font.Font(None,60)
clock = pygame.time.Clock()
pos_v=[]
pos_e = []
pos_mm = []

pos_v=pos_e=pos_mm=[] 
roll_v = roll_e = roll_m = 0  
roll_3=roll_4=roll_5=roll_6=roll_7=roll_8=0 
las_x = las_y = 0 
win_x = win_y = 0
button = False

WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)

pygame.display.set_caption("Resetting Space")
Earth_img = pygame.image.load('.\\data\\Earth.png')
Earth_d = 30
Moon_img = pygame.image.load('.\\data\\Moon.png')
Moon_d = 15
Sun_img = pygame.image.load('.\\data\\Sun.png')
Sun_d = 100

while True:
    Earth = pygame.transform.scale(Earth_img, (int(Earth_d), int(Earth_d)))
    Sun = pygame.transform.scale(Sun_img, (int(Sun_d), int(Sun_d)))
    Moon = pygame.transform.scale(Moon_img, (int(Moon_d), int(Moon_d)))

    for event in pygame.event.get():
        if event.type == VIDEORESIZE:
            size = event.dict['size']
            position = size[0]//2, size[1]//2
            screen = pygame.display.set_mode(size, RESIZABLE)
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                button = True
                las_x,las_y = event.pos
            if event.button == 4:
                Sun_d *= 1.1
                Earth_d *= 1.1
                Moon_d *= 1.1
            if event.button == 5:
                Sun_d *= 0.9
                Earth_d *= 0.9
                Moon_d *= 0.9
        if event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:button = False
        if event.type == pygame.MOUSEMOTION and event.buttons[0] == 1 and button == True:
            win_x -= las_x - event.pos[0]
            win_y -= las_y - event.pos[1]
            las_x,las_y = event.pos

    screen.fill(WHITE)

    if Sun_d >= 13:
        screen.blit(Sun,[size[0]//2-Sun_d/2+win_x,size[1]//2-Sun_d/2+win_y])


    roll_e += 0.001
    pos_e_x = int(size[0]//2 + size[1]//2*math.sin(roll_e)*Earth_d/30)
    pos_e_y = int(size[1]//2 + size[1]//2*math.cos(roll_e)*Earth_d/30)
    
    if Earth_d >= 13:
        screen.blit(Earth,[pos_e_x-Earth_d/2+win_x, pos_e_y-Earth_d/2+win_y])
  
    roll_m += 0.005
    pos_m_x = int(pos_e_x + size[1]//15*math.sin(roll_m)*Moon_d/15)
    pos_m_y = int(pos_e_y + size[1]//15*math.cos(roll_m)*Moon_d/15)
    if Moon_d >= 13:
        screen.blit(Moon,[pos_m_x-Moon_d/2+win_x, pos_m_y-Moon_d/2+win_y])

    pygame.display.flip()  
    clock.tick(100)  
pygame.quit()